package cn.tedu.aop.demo;

import org.springframework.stereotype.Component;

@Component
public class CalculatorImpl implements Calculator{
    @Override
    public int add(int x,int y){
        int a=x+y;
        System.out.println(x+"+"+y+"="+a);
        return a;
    }
    @Override
    public double add(double x,double y){
//        return x+y;
        double result = x + y;
        System.out.println(x+"+"+y+"="+result);
        return result;
    }
    @Override
    public String add(String x,String y){
//        return String.valueOf(Double.parseDouble(x)+Double.parseDouble(y));
        String result = String.valueOf(Double.parseDouble(x)+Double.parseDouble(y));
        System.out.println(x+"+"+y+"="+result);
        return result;
    }
    @Override
    public int sub(int x,int y){
//        return x-y;
        int result = x - y;
        System.out.println(x+"-"+y+"="+result);
        return result;
    }
    @Override
    public int mul(int x,int y){
//        return x*y;
        int result = x * y;
        System.out.println(x+"*"+y+"="+result);
        return result;
    }
    @Override
    public int div(int x,int y){
//        return x/y;
        if (y==0){
            throw new RuntimeException("除数不能为0");
        }
        int result = x / y;
        System.out.println(x+"/"+y+"="+result);
        return result;
    }

//    @Override
//    public String toString() {
//        return "CalculatorImpl{}";
//    }
}
